﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using System.Configuration;
using System.Security.Principal;

namespace HyperLocal.Core
{
    public partial class LocalOrbUser : MembershipUser, IIdentity, IPrincipal
    {
        public bool IsInRole(string role)
        {
            bool retvalue = false;
            foreach (var entity in this.LocalOrbRolesXrefs)
            {
                if (entity.LocalOrbRole.RoleName.ToUpper() == role.ToUpper())
                {
                    retvalue = true;
                    break;
                }
            }

            return retvalue;
        }

        public bool IsAdmin
        {
            get
            {
                bool retvalue = false;
                foreach (var entity in this.LocalOrbRolesXrefs)
                {
                    if (entity.LocalOrbRole.RoleName.ToUpper() == "SUPERADMINISTRATOR")
                    {
                        retvalue = true;
                        break;
                    }
                }

                return retvalue;
            }
        }

        #region IIdentity Members

        public string AuthenticationType
        {
            get { return "LocalOrbUser"; }
        }

        public bool IsAuthenticated
        {
            get { return this.IsApproved; }
        }

        public string Name
        {
            get { return this.UserName; }
        }

        #endregion

        #region IPrincipal Members

        public IIdentity Identity
        {
            get
            {
                return this;
            }
        }

        #endregion
    }
}
